<template>
  <div class="process-inspection-todo-page">
    <div class="page-header"></div>
    <div class="page-container">
      <div class="table-header" header="待办事项"></div>
      <div class="table-list">
        <vxe-table
          height="99%"
          class="scrollbarStyle"
          align="center"
          :data="tableData"
          :column-config="{ resizable: true }"
          show-overflow
          show-header-overflow
        >
          <vxe-column type="seq" width="80" title="序号"></vxe-column>
          <vxe-column field="snapType" title="抓拍类型"> </vxe-column>
          <vxe-column field="snapTime" title="抓拍时间"> </vxe-column>
          <vxe-column field="approver" title="审批人"> </vxe-column>
          <vxe-column title="状态">
            <template #default="{ row }">
              <div :class="[checkStatusClass(row), 'status-text']">
                {{ checkStatusName(row) }}
              </div>
            </template>
          </vxe-column>
          <vxe-column field="operate" width="220" title="操作" fixed="right">
            <template #default="{ row }">
              <div class="text-button-group">
                <a-button
                  type="link"
                  v-if="row.distribution"
                  @click="gotoDistribute(row)"
                >
                  分配
                </a-button>
                <a-button
                  type="link"
                  v-if="row.handle"
                  @click="gotoView(row, 0)"
                >
                  处理
                </a-button>
                <a-button
                  type="link"
                  v-if="row.approve"
                  @click="gotoView(row, 1)"
                >
                  审批
                </a-button>
                <a-button type="link" @click="snapImg(row)">
                  抓拍图片
                </a-button>
              </div>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div>
        <vxe-pager
          background
          :current-page.sync="pager.page"
          :page-size.sync="pager.pageSize"
          :total="pager.total"
          :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'Sizes', 'FullJump']"
          @page-change="paginationChange"
        >
          <template #left>
            <div class="vxe-pager-left-tip-container">
              第<span>1</span>到<span
                >{{ Math.ceil(pager.total / pager.pageSize) || 1 }}页 </span
              >共<span>{{ pager.total }}</span
              >条记录
            </div>
          </template>
        </vxe-pager>
      </div>
    </div>
    <!-- 详情页面 -->
    <customModal :visible.sync="pageVisible" :parameter="parameter">
    </customModal>
    <!-- 分配弹窗 -->
    <distributeModal
      :visible.sync="distributeVisible"
      :parameter="parameter"
    ></distributeModal>
    <!-- 抓怕图片 -->
    <snapPictureModal
      :visible.sync="pictureVisible"
      :previewImgs="path"
    ></snapPictureModal>
  </div>
</template>

<script>
import customModal from "./components/customModal";
import distributeModal from "./components/distributeModal";
import snapPictureModal from "./components/snapPictureModal";
import { getAQZPList } from "@/api/todo";
export default {
  components: {
    customModal,
    distributeModal,
    snapPictureModal,
  },
  props: ["isMenuCode"],
  inject: ["upLeave"],
  watch: {
    isMenuCode: {
      handler(val) {
        if (val == "AQZP") {
          this.getData();
        }
      },
      immediate: true,
      deep: true,
    },
  },
  data() {
    return {
      loading: false,
      tableData: [],
      pager: {
        page: 1,
        pageSize: 10,
        total: 0,
      },
      //查看
      pageVisible: false,
      //分配
      distributeVisible: false,
      //抓怕图片
      pictureVisible: false,
      parameter: {},
      path: [],
    };
  },
  methods: {
    //抓拍图片
    snapImg(row) {
      let { picture } = row;
      this.path = [picture];
      this.pictureVisible = true;
    },
    gotoDistribute(row) {
      this.parameter = row;
      this.distributeVisible = true;
    },
    gotoView(row, operate) {
      this.parameter = {
        ...row,
        operate,
      };
      this.pageVisible = true;
    },

    getData() {
      this.upLeave.getTodoData();
      this.pager.page = 1;
      this.getTableData();
    },
    //查询列表
    getTableData() {
      this.loading = true;
      let { page, pageSize } = this.pager;
      return new Promise((resolve, reject) => {
        getAQZPList({
          page,
          pageSize,
        })
          .then((res) => {
            let { data } = res;
            this.tableData = data.result?.rows || [];
            this.pager.total = data?.result?.total || 0;
            resolve();
          })
          .catch((_) => {
            this.tableData = [];
            this.pager.total = 0;
            reject();
          })
          .finally((_) => {
            this.loading = false;
          });
      });
    },
    //监听分页切换
    paginationChange({ currentPage, pageSize }) {
      this.pager.page = currentPage;
      this.pager.pageSize = pageSize;
      this.getTableData();
    },

    //校验状态名称
    checkStatusName(row) {
      let { testNode, approvlStatus } = row;
      switch (testNode) {
        case "1":
          if (approvlStatus == 0) {
            return "待分配";
          } else {
            return "-";
          }

        case "2":
          if (approvlStatus == 0) {
            return "处理中";
          } else {
            return "-";
          }

        case "3":
          if (approvlStatus == 1) {
            return "审批中";
          } else {
            return "-";
          }

        case "4":
          if (approvlStatus == 2) {
            return "已完成";
          } else if (approvlStatus == 3) {
            return "驳回";
          } else {
            return "-";
          }

        default:
          return "--";
      }
    },

    //校验状态className
    checkStatusClass(row) {
      let { testNode, approvlStatus } = row;
      switch (testNode) {
        case "1":
          if (approvlStatus == 0) {
            return "lock";
          } else {
            return "cancel";
          }

        case "2":
          if (approvlStatus == 0) {
            return "warn";
          } else {
            return "cancel";
          }

        case "3":
          if (approvlStatus == 1) {
            return "approv";
          } else {
            return "cancel";
          }

        case "4":
          if (approvlStatus == 2) {
            return "normal";
          } else if (approvlStatus == 3) {
            return "error";
          } else {
            return "cancel";
          }

        default:
          return "cancel";
      }
    },
  },
};
</script>

<style lang="less" scoped>
.process-inspection-todo-page {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  .page-header {
    .conditions-screening-container {
      box-shadow: none;
    }
    margin-bottom: 10px;
  }
  .page-container {
    flex: 1;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    .table-header {
      padding: 20px 20px;
      box-sizing: border-box;
      .flex();
      justify-content: space-between;
      align-items: center;
      &::before {
        content: attr(header);
        height: 18px;
        border-left: 3px solid var(--primary-color);
        padding-left: 10px;
        font-size: 18px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #525a5d;
        line-height: 18px;
      }
    }
    .table-list {
      flex: 1;
      height: 100%;
      .status-text {
        border-radius: 4px;
        color: #fff;
        .flex();
        align-items: center;
        justify-content: center;
        margin: 0 auto;
        font-size: 12px;
        width: 80px;
        &.lock {
          background: #0098ff;
        }
        &.warn {
          background: #ff993f;
        }
        &.approv {
          background: #ff7113;
        }
        &.normal {
          background: #4bc964;
        }
        &.error {
          background: #ff3f4a;
        }
        &.cancel {
          background: #f1f2f7;
          color: #aab0bc;
        }
      }
    }
  }
}
</style>
